define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            Table.api.init({
                extend: {
                    index_url: 'scanwork/stocktransaction/index' + location.search,
                    add_url: 'scanwork/stocktransaction/add',
                    table: 'scanwork_stock_transaction',
                }
            });

            var table = $("#table");

            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: 'ID'},
                        {field: 'transaction_no', title: '单据号'},
                        {field: 'transaction_type', title: '类型', searchList: {1:'采购入库',2:'生产入库',3:'其他入库',4:'销售出库',5:'生产领料',6:'其他出库',7:'调拨',8:'盘点'}},
                        {field: 'operator_name', title: '操作员'},
                        {field: 'status', title: '状态', searchList: {0:'草稿',1:'待审核',2:'已审核',3:'已完成',4:'已取消'}, formatter: Table.api.formatter.status},
                        {field: 'transaction_time', title: '业务时间', formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
